<template>
  <div>
    <div class="right">
      <a href="javascript:void (0)" v-routers="{path:'/'}"></a>
    </div>
    <div class="card">
      <el-input style="width: 260px;margin-right: 10px" placeholder="请输入班级名称"></el-input>
      <el-button class="defaultBtn" icon="el-icon-search" color="#333" type="info">查询</el-button>
      <el-button class="defaultBtn" icon="el-icon-refresh-right"  type="info">重置</el-button>
    </div>
    <div class="card">
      <el-button @click="dialogVisibleClass=true" class="defaultBtn" icon="el-icon-plus"  type="info">新增</el-button>
    </div>

    <el-table :data="tableData" border style="width: 100%">
      <el-table-column type="index" label="序号" width="80"/>
      <el-table-column prop="class" label="班级名称" min-width="180"></el-table-column>
      <el-table-column prop="major" label="专业名称" min-width="180"></el-table-column>
      <el-table-column prop="status" label="状态" min-width="180">
        <template #default="{row}">{{type(row)}}</template>
      </el-table-column>
      <el-table-column prop="crateTime" label="创建时间" min-width="180"></el-table-column>
      <el-table-column fixed="right" align="center" label="操作" width="350">
        <el-button size="mini" class="defaultBtn" type="info" @click="viewDetail">查看详情</el-button>
        <el-button size="mini" class="defaultBtn" type="info" @click="addStudent">添加学生</el-button>
        <el-button size="mini" class="defaultBtn" type="info">编辑</el-button>
        <el-button size="mini" class="defaultBtn" type="info">删除</el-button>
      </el-table-column>
    </el-table>
    <div class="page">
      <el-pagination background layout="prev, pager, next" :total="1000"></el-pagination>
    </div>


    <el-dialog title="查看学生详情" :visible.sync="dialogVisible" width="1300px" :before-close="handleClose">
      <el-table @selection-change="handleSelectionChange" ref="multipleTable" :data="tableData" border style="width: 100%">
        <el-table-column type="selection" v-if="!isDetail" width="55"></el-table-column>
        <el-table-column prop="name" label="用户名称" min-width="180"></el-table-column>
        <el-table-column prop="class" label="班级名称" min-width="180"></el-table-column>
        <el-table-column prop="major" label="专业名称" min-width="180"></el-table-column>
        <el-table-column prop="type" label="用户类型" min-width="180">
          <template #default="{row}">{{typeStudent(row)}}</template>
        </el-table-column>
        <el-table-column prop="crateTime" label="创建时间" min-width="180"></el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="info" class="defaultBtn" @click="dialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>

    <el-dialog title="班级管理" :visible.sync="dialogVisibleClass" width="600px" :before-close="handleCloseClass">
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="班级名称">
          <el-input v-model="form.name" placeholder="请输入班级名称"></el-input>
        </el-form-item>
        <el-form-item label="专业名称">
          <el-input v-model="form.name" placeholder="请输入专业名称"></el-input>
        </el-form-item>
        <el-form-item label="班级状态">
          <el-radio-group v-model="form.resource">
            <el-radio :label="0">启用</el-radio>
            <el-radio :label="1">禁用</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisibleClass = false">取 消</el-button>
        <el-button type="info" class="defaultBtn" @click="dialogVisibleClass = false">确 定</el-button>
      </span>
    </el-dialog>


  </div>
</template>

<script>
export default {
  data() {
    return {
      dialogVisible:false,
      dialogVisibleClass:false,
      multipleSelection: [],
      isDetail:false,
      tableData: [{name:'张三丰',class:'计算机科学与网络3班',major:'计算机科学与网络',status:0,type:0,crateTime:'2022-12-31 12:00:00'}],
      form: {
        name: '',
        region: '',
        date1: '',
        date2: '',
        delivery: false,
        type: [],
        resource: 0,
        desc: ''
      }
    }
  },
  methods:{
    type(item){
      console.log(item)
      switch (item.status){
        case 0:{
          return '禁用'
        }
        case 1:{
          return  '启用'
        }
      }
    },
    typeStudent(item){
      console.log(item)
      switch (item.type){
        case 0:{
          return '学生'
        }
        case 1:{
          return  '老师'
        }
      }
    },
    viewDetail(){
      this.isDetail=true
      this.dialogVisible=true
    },
    addStudent(){
      this.isDetail=false
      this.dialogVisible=true
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    handleClose(){
      this.dialogVisible=false
    },
    handleCloseClass(){
      this.dialogVisibleClass=false
    }
  }
}
</script>

<style scoped lang="scss">

.card{
  width: 100%;
  margin: 10px 0;
}
.page{
  width: 100%;
  display: flex;
  justify-content: right;
  margin-top: 10px;
}
::v-deep(.el-pagination.is-background .el-pager li:not(.disabled).active ){
  background: #333 !important;
  color: #fff;
}
</style>
